﻿@using Orchard.ContentManagement;
@using Orchard.Core.Contents;

@{
    Script.Require("ShapesBase");
    ContentItem contentItem = Model.ContentItem;
    var hasPublished = contentItem.HasPublished();
    var hasDraft = contentItem.HasDraft();
    var isPublished = contentItem.IsPublished();
    var authorizedToEdit = Authorizer.Authorize(Permissions.EditContent, contentItem);
    var authorizedToDelete = Authorizer.Authorize(Permissions.DeleteContent, contentItem);
    var authorizedToPublish = Authorizer.Authorize(Permissions.PublishContent, contentItem);
}

<ul class="action-links action-links-item">
    @if (hasPublished) {
        <li class="action-link">
            @Html.ItemDisplayLink(T("View").Text, contentItem)
        </li>
    }
    @if (authorizedToEdit) {
        if (hasPublished) {
            if (!hasDraft) { 
                <li class="action-link">
                    @Html.ItemEditLink(T("Edit").Text, contentItem)
                </li>
            }
            <li class="action-link">
                @Html.ActionLink(T("Clone").Text, "Clone", "Admin", new { Id = contentItem.Id, Area = "Contents" }, new { itemprop = "UnsafeUrl" })
            </li>
        }

        if (hasPublished && authorizedToPublish) {
            <li class="action-link">
                @Html.Link(T("Unpublish").Text, Url.Action("Unpublish", "Admin", new {area = "Contents", id = contentItem.Id, returnUrl = Request.RawUrl}), new {itemprop = "UnsafeUrl"})
            </li>
        }

        if (authorizedToDelete) {
            <li class="action-link">
                @Html.Link(T("Delete").Text, Url.ItemRemoveUrl(contentItem, new { returnUrl = Request.RawUrl }), new { itemprop = "RemoveUrl UnsafeUrl" })
            </li>
        }
    }
</ul>

@if ((!isPublished || hasDraft) && authorizedToEdit) {
    <ul class="action-links action-links-draft">
        <li class="action-label">
            @T("Draft:")
        </li>
        @if (!isPublished && Authorizer.Authorize(Permissions.PreviewContent, contentItem)) {
            <li class="action-link">
                @Html.ActionLink(T("View").Text, "Display", "Item", new { area = "Contents", id = contentItem.Id, version = contentItem.Version }, new { })
            </li>
        }

        <li class="action-link">
            @Html.ItemEditLink(T("Edit").Text, contentItem)
        </li>

        @if (hasDraft && authorizedToPublish) {
            <li class="action-link">
                @Html.ActionLink(T("Publish").Text, "Publish", "Admin", new { area = "Contents", id = contentItem.Id, returnUrl = Request.RawUrl }, new { itemprop = "UnsafeUrl" })
            </li>
        }

        @if (!isPublished && hasPublished && authorizedToDelete) {
            <li class="action-link">
                @Html.ActionLink(T("Discard").Text, "DiscardDraft", "Admin", new { area = "Contents", id = contentItem.Id, returnUrl = Request.RawUrl }, new { itemprop = "RemoveUrl UnsafeUrl" })
            </li>
        }
    </ul>
}